<template>
	<view>
		<headertop></headertop>
		<view class="mainpadding_top margin_top6">
			<view class="mainpadding_top margin_top6">
				<view class="margin_top6 xiaohei fonweight" style="font-size: 50rpx;">{{$t('login.dl')}}</view>
				<view class="bigtext xiaohui margin_top">{{$t('login.hydl')}} APP</view>
				<view class="ershiba xiahuaxian" style="margin-top: 100rpx;">
					<input type="number" :placeholder="$t('login.qsrsjh')" style="width: 100%;" v-model="phone">
				</view>
				<view class="margin_top5 ershiba xiahuaxian flexbetween">
					<input type="number" :placeholder="$t('login.qsryzm')" style="width: 50%;" v-model="code">
					<view class="xiaolan ershil textcenter" style="width: 240rpx;" @click="sendyzm"
						v-show="codetext == 1">{{$t('login.hqyzm')}}</view>
					<view class="xiaolan ershil textcenter" style="width: 240rpx;" v-show="codetext == 2">{{second}}s
					</view>
					<view class="xiaolan ershil textcenter" style="width: 240rpx;" @click="sendyzm"
						v-show="codetext == 3">{{$t('login.cxfs')}}</view>
				</view>
				<view class="margin_top5 ershiba xiahuaxian">
					<input type="number" :placeholder="$t('login.qsrxlh')" style="width: 100%;" v-model="invitedCode">
				</view>
				<view class="bigbtn" style="margin-top: 100rpx;height: 120rpx;background-color: #9dccff;"
					@click="login">{{$t('login.dl')}}</view>
				<!-- <view style="margin-top: 100rpx;" class="flexbetween">
					<view class="" style="padding: 15rpx;border-radius: 50%;border: 1rpx solid #F0F0F0;">
						<u-icon name="weixin-fill" color="#909399" size="38"  @click="jumpurl('/pages/mine/shezhi')"></u-icon>
					</view>
					<view class="flexcenter" style="width: 80%;border-radius: 100rpx;padding: 15rpx 0;border: 1rpx solid #F0F0F0;">
						<u-icon name="apple-fill" color="#909399" size="38"  @click="jumpurl('/pages/mine/shezhi')"></u-icon>
						<view class="xiaohui ershiba">通过Apple登录</view>
					</view>
				</view> -->
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding" @click="type = !type">
			<view class="flexcenter">
				<!-- 已选中 -->
				<view class="margin_right1" v-show="type">
					<u-icon name="checkmark-circle-fill" color="#2979ff" size="16"></u-icon>
				</view>
				<!-- 为选中 -->
				<view class="margin_right1" v-show="!type">
					<u-icon name="checkmark-circle-fill" color="#999" size="16"></u-icon>
				</view>
				<view class="">
					<text class="strongtext xiaohui">{{$t('login.wyyd')}}</text>
					<text class="strongtext xiaolan fonweight" @click.stop="jumpurl('/pages/system/system?type=1')">
						{{$t('login.yhxy')}}
					</text>
					<text class="strongtext xiaohui"> {{$t('login.h')}} </text>
					<text class="strongtext xiaolan fonweight" @click.stop="jumpurl('/pages/system/system?type=2')">
						{{$t('login.yszc')}}
					</text>
				</view>
			</view>
		</view>
		<!-- 申请位置弹框 -->
		<u-popup :show="shiyonglc" round="10" mode="center" @close="shiyonglc=false">
			<view class="mainpadding4" style="width: 500rpx;">
				<!-- mapStatus// 点位状态 0-未申请 1-待审核 2-审核通过 3-审核拒绝 -->
				<!-- confirmaStatus// 确权码状态 0-未申请 1-已申请待支付 2-已通过 -->
				<view class="sanshier textcenter fonweight xiaohei">{{$t('login.sylc')}}</view>
				<view class="ershiba xiaohuang margin_top" :class="shAll.mapStatus==0?'xiaohuang':'qiqiqi'">{{$t('login.nr1')}}
				</view>
				<view class="smalltext xiaohui margin_top2">{{$t('login.content1')}}</view>
				<view class="ershiba margin_top" :class="shAll.mapStatus==1?'xiaohuang':'qiqiqi'">{{$t('login.nr2')}}</view>
				<view class="smalltext xiaohui margin_top2">{{$t('login.content2')}}</view>
				<view class="ershiba margin_top"
					:class="shAll.mapStatus==2 && (shAll.confirmaStatus==0 || shAll.confirmaStatus==1) ?'xiaohuang':'qiqiqi'">
					{{$t('login.nr3')}}</view>
				<view class="smalltext xiaohui margin_top2">{{$t('login.content3')}}</view>
				<view class="ershiba margin_top" :class="shAll.mapStatus==3?'xiaohuang':'qiqiqi'">{{$t('login.nr4')}}
				</view>
				<view class="smalltext xiaohui margin_top2">{{$t('login.content4')}}</view>
				<view class="ershiba margin_top"
					:class="shAll.mapStatus==3 && shAll.confirmaStatus==2?'xiaohuang':'qiqiqi'">{{$t('login.nr5')}}</view>
				<view class="sanshier textcenter margin_top5 fonweight xiaolan" v-if="shAll.mapStatus==0"
					@click="shiyonglc=false;shenqwz=true;">{{$t('login.qd')}}</view>
				<view class="sanshier textcenter margin_top5 fonweight xiaolan" v-else-if="shAll.mapStatus==1"
					@click="shiyonglc=false;jumpurl('/pages/index/checkAddress')">{{$t('login.ck')}}</view>
				<view class="sanshier textcenter margin_top5 fonweight xiaolan"
					v-else-if="shAll.mapStatus==2 && (shAll.confirmaStatus==0 || shAll.confirmaStatus==1)"
					@click="shiyonglc=false;quequanzf=true">{{$t('login.qd')}}</view>
					<view class="sanshier textcenter margin_top5 fonweight xiaolan" v-else-if="shAll.mapStatus==3"
						@click="shiyonglc=false;jumpurl('/pages/index/checkAddress')">{{$t('login.ck')}}</view>
				<view class="sanshier textcenter margin_top5 fonweight xiaolan" v-else @click="shiyonglc=false;">{{$t('login.gb')}}
				</view>
			</view>
		</u-popup>
		<u-popup :show="shenqwz" round="10" mode="center">
			<view class="mainpadding4 flexcolumn" style="width: 500rpx;">
				<view class="sanshier fonweight xiaohei">{{$t('login.xzdz')}}</view>
				<view class="margin_top xiaohei ershiba textcenter">{{$t('login.xzdzms')}}</view>
				<view class="sanshier margin_top5 fonweight xiaolan"
					@click="shenqwz=false;jumpurl('/pages/index/checkAddress')">{{$t('login.qd')}}</view>
			</view>
		</u-popup>
		<u-popup :show="quequanzf" round="10" mode="center">
			<view class="mainpadding4 flexcolumn" style="min-width: 500rpx;">
				<view class="sanshier fonweight xiaohei">{{$t('login.ljqq')}}</view>
				<view class="margin_top xiaohei ershiba">{{$t('login.zf')}}<text
						class="xiaolan fonweight">{{price}}</text>{{$t('login.sqdtgc')}}</view>
				<view class="sanshier margin_top5 fonweight xiaolan"
					@click="quequanzf=false;jumpurl('/pages/index/pay?type=2')">{{$t('login.qzf')}}</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: false,
				phone: "",
				code: "",
				invitedCode: "",
				codetext: 1,
				second: 59,
				shenqwz: false, //申请位置弹框
				quequanzf: false,
				price: "",
				shiyonglc: false,
				shAll: {}
			}
		},
		onLoad() {
			this.getprice()
		},
		methods: {
			getprice() {
				httpRequest.request('/api/v1/protocol/getProtocol', 'GET', {
					protocolType: "comfire_price"
				}).then(res => {
					if (res.code == 200) {
						this.price = res.data.protocolContent
					}
				})
			},
			login() {
				if (this.phone == "") {
					httpRequest.toast(this.$t('login.qsrsjh'));
					return false;
				}
				// if (!this.isMobile(this.phone)) {
				// 	httpRequest.toast(this.$t('login.sjcw'))
				// 	return;
				// }
				if (this.code == "") {
					httpRequest.toast(this.$t('login.qsryzm'));
					return false;
				}
				if (!this.type) {
					httpRequest.toast(this.$t('login.rzyd'));
					return false;
				}
				// if(this.invitedCode==""){
				// 	httpRequest.toast("请输入序列号")
				// 	return false
				// }
				let that = this
				uni.showLoading({
					mask: true,
					title: "Loading"
				})
				httpRequest.request('/api/v1/auth/phoneLogin', 'POST', {
					phone: this.phone,
					code: this.code,
					invitedCode: this.invitedCode,
				}).then(res => {
					uni.hideLoading()
					console.log(res);
					if (res.code == 200) {
						this.shAll = res.data
						uni.setStorageSync('token', res.data.accessToken);
						uni.setStorageSync('user_id', res.data.userId);
						// 点位状态 0-未申请 1-待审核 2-审核通过 3-审核拒绝
						uni.setStorageSync('mapStatus', res.data.mapStatus);
						// 确权码状态 0-未申请 1-已申请待支付 2-已通过
						uni.setStorageSync('confirmaStatus', res.data.confirmaStatus);
						if (res.data.mapStatus == 0 || res.data.mapStatus == 1) { //未申请点位
							this.shiyonglc = true
							// this.shenqwz = true
							return false
						}
						if (res.data.mapStatus == 3) { //点位审核拒绝
						this.shiyonglc = true
							return false
						}
						if (res.data.confirmaStatus == 1) { //未申请点位
							this.shiyonglc = true
							// this.quequanzf = true
							return false
						}
						if (res.data.confirmaStatus == 2) {
							httpRequest.toast(this.$t('login.dlcg'));
							setTimeout(() => {
								uni.reLaunch({
									url: "/pages/index/index"
								})
							}, 1000)
						}
					} else {
						httpRequest.toast(res.msg);
					}
				})
			},
			//验证手机号
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value);
				return a;
			},
			//发送验证码
			sendyzm() {
				let _this = this;
				if (this.phone == "") {
					httpRequest.toast(this.$t('login.qsrsjh'));
					return false;
				}
				// if (!this.isMobile(this.phone)) {
				// 	httpRequest.toast(this.$t('login.sjcw'))
				// 	return;
				// }
				let device = uni.getSystemInfoSync();
				httpRequest.request('/api/v1/auth/getCode', 'GET', {
					phone: this.phone,
				}, false, true, false).then(res => {
					console.log(res);
					if (res.code == 1) {
						_this.codetext = 2;
						_this.second = 59;
						let timer = setInterval(function() {
							if (_this.second > 1) {
								_this.second--;
							} else {
								clearInterval(timer);
								_this.codetext = 3;
							}
						}, 1000)
						httpRequest.toast('发送成功')
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
		}
	}
</script>